//
//  LLThirdLoginView.m
//  banquet
//
//  Created by 肖兰月 on 2017/12/6.
//  Copyright © 2017年 iiHorizon. All rights reserved.
//

#import "LLThirdLoginView.h"
//#import "LLWebviewViewController.h"

@interface LLThirdLoginView ()
@property (strong, nonatomic) UILabel *label;
@property (strong, nonatomic) CALayer *leftLine;
@property (strong, nonatomic) CALayer *rightLine;
@property (weak, nonatomic) LLButton *agreeBtn;
@property (weak, nonatomic) LLButton *protocolBtn;

@property (strong, nonatomic) NSMutableArray *btns;
@end

@implementation LLThirdLoginView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self initSubViews];
    }
    return self;
}

- (NSMutableArray *)btns {
    if (_btns == nil) {
        _btns = [NSMutableArray array];
    }
    return _btns;
}

- (void)initSubViews {
    _label = [UILabel new];
    _label.text = @"快速登录";
    _label.textColor = LLColorRGB(200);
    _label.font = [UIFont systemFontOfSize:12];
    _label.textAlignment = NSTextAlignmentCenter;
    [self addSubview:_label];
    
    _leftLine = [CALayer layer];
    _leftLine.backgroundColor = LLColorRGB(211).CGColor;
    [self.layer addSublayer:_leftLine];
    
    _rightLine = [CALayer layer];
    _rightLine.backgroundColor = LLColorRGB(211).CGColor;
    [self.layer addSublayer:_rightLine];

    
//    CGFloat navH = LLNavH;
//    LLButton *agreeBtn = [LLButton new];
////    [agreeBtn setImage:[UIImage imageNamed:@"银行卡-不同意协议"] forState:0];
////    [agreeBtn setImage:[UIImage imageNamed:@"银行卡-同意协议"] forState:UIControlStateSelected];
//    [agreeBtn setTitle:@"登录即表示同意" forState:0];
//    agreeBtn.titleLabel.font = [UIFont systemFontOfSize:14];
//    [agreeBtn setTitleColor:LLColorRGB(102) forState:0];
//    agreeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
////    agreeBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
//    agreeBtn.userInteractionEnabled = NO;
//    [self addSubview:agreeBtn];
//    self.agreeBtn = agreeBtn;
//
//    LLButton *protocolBtn = [LLButton new];
//    protocolBtn.frame = CGRectMake(agreeBtn.right, LLScreenHeight - navH - 30 - 30, 150, 30);
//    [protocolBtn setTitle:@"《用户协议》" forState:0];
//    protocolBtn.titleLabel.font = [UIFont systemFontOfSize:14];
//    [protocolBtn setTitleColor:LLMainColor forState:0];
//    [protocolBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
//    [protocolBtn addTarget:self action:@selector(protocolBtnClick) forControlEvents:UIControlEventTouchUpInside];
//    [self addSubview:protocolBtn];
//    self.protocolBtn = protocolBtn;
}

- (void)setImgs:(NSArray *)imgs {
    _imgs = imgs;
    for (NSInteger i = 0; i < imgs.count; i++) {
        UIButton *btn = [self inittBtnWithImg:imgs[i]];
        btn.tag = i;
    }
}

- (LLButton *)inittBtnWithImg:(NSString *)img {
    LLButton *btn = [LLButton new];
    [btn setImage:[UIImage imageNamed:img] forState:0];
    [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btn];
    [self.btns addObject:btn];
    return btn;
}

- (void)btnClick:(UIButton *)btn {
    if (self.didClickBtnBlock) {
        self.didClickBtnBlock(btn.tag);
    }
}

//- (void)protocolBtnClick {
//    LLWebviewViewController *vc = [[LLWebviewViewController alloc] init];
//    vc.titleStr = @"用户协议";
//    vc.url = ApiUserProtocol;
//    vc.showByPresent = YES;
//    LLNavViewController *nav = [[LLNavViewController alloc] initWithRootViewController:vc];
//    [[UIViewController currentViewController] presentViewController:nav animated:YES completion:nil];
//}

- (void)agreeBtnClick {
    
}

- (void)layoutSubviews {
    [super layoutSubviews];
    _label.frame = CGRectMake((self.width - 80)/2.0, 0, 80, 20);
    _leftLine.frame = CGRectMake(40, (20 - 0.7)/2.0, _label.left - 40, 0.7);
    _rightLine.frame = CGRectMake(_label.right, (20 - 0.7)/2.0, self.width-40-_label.right, 0.7);
    if (!self.imgs.count) return;
    CGFloat marginOfInside = 50;
    CGFloat btnX = 0;
    CGFloat btnWH = 44;
    CGFloat btnY = _label.bottom + 15;
    CGFloat btnCount = self.imgs.count;
    CGFloat left = (self.width - marginOfInside*(btnCount-1) - btnCount * btnWH)/(btnCount-1);
    for (NSInteger i = 0; i < btnCount; i++) {
        LLButton *btn = self.btns[i];
        btnX = left + (marginOfInside + btnWH) * i;
        btn.frame = CGRectMake(btnX, btnY, btnWH, btnWH);
    }
//    self.agreeBtn.frame = CGRectMake(LLScreenWidth/2.0 - 130, self.height - 20 - 30, 130, 30);
//    self.protocolBtn.frame = CGRectMake(self.agreeBtn.right, self.height - 20 - 30, 150, 30);
}

@end
